package com.manjusaka.structure7.Facade;

/**
 * 外观模式是为了处理一个类和多个类相互交互的情况
 * Created by manjusaka on 2017/7/5.
 */
public class FacadePattern {
    public static void main(String[] args) {
        Facade Facade = new Facade(new Decoder(), new Encoder(), new ReaderAndWriter());
        Facade.exportData();
        Facade.importData();
    }
}

class Decoder {
    public void decode() {
        System.out.println("解码");
    }
}

class Encoder {
    public void encode() {
        System.out.println("编码");
    }
}

class ReaderAndWriter {
    public void read() {
        System.out.println("读数据");
    }

    public void write() {
        System.out.println("写数据");
    }
}

class Facade {
    private Decoder Decoder;
    private Encoder Encoder;
    private ReaderAndWriter ReaderAndWriter;

    public Facade(Decoder Decoder, Encoder Encoder, ReaderAndWriter ReaderAndWriter) {
        this.Decoder = Decoder;
        this.Encoder = Encoder;
        this.ReaderAndWriter = ReaderAndWriter;
    }

    public void exportData() {
        Decoder.decode();
        ReaderAndWriter.read();
    }

    public void importData() {
        Encoder.encode();
        ReaderAndWriter.write();
    }
}